<keira-top-bar [selected]="handlerService.selected" [selectedName]="handlerService.selectedName" [isNew]="handlerService.isNew" />

<div class="container-fluid editor-with-preview" [class.show-preview]="questPreviewService.showPreview">
  @if (editorService.loading) {
    <span [translate]="'LOADING'"></span>
  }

  @if (editorService.form && !!editorService.loadedEntityId && !editorService.loading) {
    <div>
      <div class="content-block">
        <keira-query-output
          [docUrl]="docUrl"
          [isNew]="editorService.isNew"
          [diffQuery]="editorService.diffQuery"
          [fullQuery]="editorService.fullQuery"
          [error]="editorService.error"
          [entityTable]="editorService.entityTable"
          [editorService]="editorService"
          (executeQuery)="save($event)"
        />
      </div>
      <div class="content-block">
        <form [formGroup]="editorService.form" class="form-group edit-form">
          <div class="row">
            <div class="form-group col-12 col-sm-6 col-md-4 col-lg-4 col-xl-4">
              <label class="control-label" for="id">ID</label>
              <i class="fas fa-info-circle ms-1" placement="auto" [tooltip]="'UNIQUE_ID' | translate: { ENTITY: 'quest' }"></i>
              <input [formControlName]="'ID'" id="id" type="number" class="form-control form-control-sm" />
            </div>
            <div class="form-group col-12 col-sm-6 col-md-4 col-lg-4 col-xl-4">
              <label class="control-label" for="locale">locale</label>
              <keira-generic-option-selector [control]="editorService.form.controls.locale" id="locale" [optionList]="QUEST_LOCALE" />
            </div>
            <div class="form-group col-12 col-sm-6 col-md-4 col-lg-4 col-xl-4">
              <label class="control-label" for="id">Title</label>
              <i class="fas fa-info-circle ms-1" placement="auto" [tooltip]="'QUEST.TEMPLATE.LOG_TITLE' | translate"></i>
              <input [formControlName]="'Title'" id="title" class="form-control form-control-sm" />
            </div>
            <div class="form-group col-12 col-sm-12 col-md-8 col-lg-9 col-xl-12">
              <label class="control-label" for="id">Details</label>
              <textarea [formControlName]="'Details'" id="details" class="form-control form-control-sm"></textarea>
            </div>
            <div class="form-group col-12 col-sm-12 col-md-8 col-lg-9 col-xl-12">
              <label class="control-label" for="id">Objectives</label>
              <textarea [formControlName]="'Objectives'" id="objectives" class="form-control form-control-sm"></textarea>
            </div>
            <div class="form-group col-12 col-sm-12 col-md-8 col-lg-9 col-xl-12">
              <label class="control-label" for="id">EndText</label>
              <textarea [formControlName]="'EndText'" id="end-text" class="form-control form-control-sm"></textarea>
            </div>
            <div class="form-group col-12 col-sm-12 col-md-8 col-lg-9 col-xl-12">
              <label class="control-label" for="id">CompletedText</label>
              <textarea [formControlName]="'CompletedText'" id="completed-text" class="form-control form-control-sm"></textarea>
            </div>
            <div class="form-group col-12 col-sm-6 col-md-6 col-lg-6 col-xl-6">
              <label class="control-label" for="id">ObjectiveText1</label>
              <input [formControlName]="'ObjectiveText1'" id="objective-text-1" class="form-control form-control-sm" />
            </div>
            <div class="form-group col-12 col-sm-6 col-md-6 col-lg-6 col-xl-6">
              <label class="control-label" for="id">ObjectiveText2</label>
              <input [formControlName]="'ObjectiveText2'" id="objective-text-2" class="form-control form-control-sm" />
            </div>
            <div class="form-group col-12 col-sm-6 col-md-6 col-lg-6 col-xl-6">
              <label class="control-label" for="id">ObjectiveText3</label>
              <input [formControlName]="'ObjectiveText3'" id="objective-text-3" class="form-control form-control-sm" />
            </div>
            <div class="form-group col-12 col-sm-6 col-md-6 col-lg-6 col-xl-6">
              <label class="control-label" for="id">ObjectiveText4</label>
              <input [formControlName]="'ObjectiveText4'" id="objective-text-4" class="form-control form-control-sm" />
            </div>
            <div class="col-12 form-error" [hidden]="editorService.isFormIdUnique()">
              <i class="fas fa-exclamation-triangle"></i>
              <span [innerHTML]="'UNIQUE' | translate: { ENTITY_SECOND_ID_FIELD: editorService.entitySecondIdField }"></span>
            </div>
          </div>
        </form>
        <div class="row">
          <div class="col-12">
            <keira-editor-buttons
              [selectedRowId]="editorService.selectedRowId"
              (deleteSelectedRow)="editorService.deleteSelectedRow()"
              (addNewRow)="editorService.addNewRow()"
              (duplicateRow)="editorService.addNewRow(true)"
            />
            <ngx-datatable
              id="editor-table"
              class="bootstrap table table-striped text-center datatable-select"
              [rows]="editorService.newRows"
              [headerHeight]="DTCFG.headerHeight"
              [footerHeight]="DTCFG.footerHeight"
              [columnMode]="DTCFG.columnMode"
              [rowHeight]="DTCFG.rowHeight"
              [selectionType]="DTCFG.selectionType"
              (select)="editorService.onRowSelection($event)"
              (keydown.delete)="editorService.deleteSelectedRow()"
            >
              <ngx-datatable-column [minWidth]="30" [maxWidth]="30" [sortable]="false">
                <ng-template let-row="row" ngx-datatable-cell-template>
                  <i [hidden]="!editorService.isRowSelected(row)" class="fas fa-chevron-right"></i>
                </ng-template>
              </ngx-datatable-column>
              <ngx-datatable-column name="Id" prop="ID" [minWidth]="80" [maxWidth]="150" />
              <ngx-datatable-column name="Locale" prop="locale" [minWidth]="200" />
              <ngx-datatable-column name="Title" prop="Title" [minWidth]="200" />
            </ngx-datatable>
          </div>
        </div>
      </div>
      <keira-quest-preview />
    </div>
  }
</div>
